package com.mj.haier.calc.repository;

import java.util.List;

import com.mj.haier.calc.domain.AzCarsGroupSettlement;
import com.mj.haier.calc.domain.AzCarsteamGroupSettlement;
import com.mj.haier.calc.domain.AzEorderSettlementProcess;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;


/**
 * Spring Data  repository for the AzEorderSettlementProcess entity.
 */
@SuppressWarnings("unused")
@Repository
public interface AzEorderSettlementProcessRepository extends JpaRepository<AzEorderSettlementProcess, Long> {


    @Query("select h.carsTeamId as carsTeamId, h.tradeCode as tradeCode, h.sourceNameCode as sourceNameCode from AzEorderSettlementProcess h where h.allCompliance = '0' and h.carsTeamSettleBatchId = '0' and h.settlementCycle = ?1 and h.tradeCode = ?2 group by h.carsTeamId, h.sourceNameCode")
    List<AzCarsteamGroupSettlement> findCarsteamGroup(String settlementCycle, String tradeCode);

    @Query("select h.carsId as carsId, h.tradeCode as tradeCode, h.sourceNameCode as sourceNameCode from AzEorderSettlementProcess h where h.allCompliance = '0' and h.carsSettleBatchId = '0' and h.settlementCycle = ?1 and h.tradeCode = ?2 group by h.carsId, h.sourceNameCode")
    List<AzCarsGroupSettlement> findCarsGroup(String settlementCycle, String tradeCode);

    List<AzEorderSettlementProcess> findAllBySettlementCycleAndTradeCodeAndSourceNameCodeAndCarsTeamIdAndAllCompliance(
        String settlementCycle, String tradeCode, String sourceNameCode, String carsTeamId, String allCompliance
    );

    List<AzEorderSettlementProcess> findAllBySettlementCycleAndTradeCodeAndSourceNameCodeAndCarsIdAndAllCompliance(
        String settlementCycle, String tradeCode, String sourceNameCode, String carsId, String allCompliance
    );

    List<AzEorderSettlementProcess> findAllBySettlementCycleAndAllComplianceIsNull(String settlementCycle, Pageable pageable);

    List<AzEorderSettlementProcess> findAllBySettlementCycleAndAllCompliance(String settlementCycle, String allCompliance, Pageable pageable);

    List<AzEorderSettlementProcess> findAllBySettlementCycleAndTradeCodeAndAllComplianceIsNull(String settlementCycle, String tradeCode, Pageable pageable);

}
